<template>
  <navbar :title="'网易严选'"></navbar>
  <div class="pay_container">
    <div class="bg"></div>
    <div class="address">
      <div class="address_item" v-for="item in addressList" :key="item.id">
        <div class="left">
          <div class="name">{{item.consignee}}</div>
          <div class="deault" v-if="item.isDefault == '1'">默认</div>
        </div>
        <div class="center">
          <div class="phone">{{ item.phoneNum }}</div>
          <address>{{ item.userAddress }}</address>
        </div>
        <div class="right">
          <van-icon name="edit" @click="ToAddressDetail(item.id)" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import type { AnyObject } from '../../api/pay'
import payApi from '../../api/pay';
import { useRouter } from 'vue-router';
const Router = useRouter()

/* 响应式数据 */
const addressList = ref<AnyObject[]>([])

/* 生命周期函数 */
onMounted(() => {
  getAddress()
})

/* 自定义事件的功能函数 */
const getAddress = async () => {
  try {
    let res = await payApi.getAddress()
    addressList.value = res.data
    console.log(addressList.value)
  } catch (error) {
    console.log(error)
  }
}

// 事件的回调
const ToAddressDetail = (id: number) => {
  Router.replace({
    name: 'AddressDetail',
    query: {
      id
    }
  })
}


</script>

<style lang="less" scoped>
.pay_container {
  .bg {
    width: 100%;
    height: 5px;
    background: url(https://yanxuan-static.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-67880192dc.png?imageView&type=webp) repeat-x;
  }

  .address {
    .address_item {
      box-sizing: border-box;
      display: flex;
      height: 75px;
      margin-left: 15px;
      border-bottom: 1px solid #999;
      padding: 20px 43px 20px 3px;
      .left {
        width: 60px;
        margin-right: 10px;
        .name {
          font-size: 14px;
          color: #333
        }
        .deault {
          margin-top: 5px;
          width: 30px;
          text-align: center;
          font-size: 12px;
          color: #DD1A21;
          border: 1px solid #DD1A21;
        }
      }

      .center {
        width: 254px;
        margin-right: 10px;
        .phone {
          font-size: 14px;
          color: #333;
        }
        address {
          font-size: 12px;
          color: #666;
        }
      }

      .right {
        position: absolute;
        right: 20px;
      }
    }
  }
}
</style>